#include<stdio.h>
#include<math.h>

int main()
{
	double a[3][3] = {{pow(10, -8), 2, 3}, { -1, 3.712, 4.623}, { -2, 1.072, 5.643}}, b[3] = {1, 2, 3}, x[3], M, temp;
	int k, i, j, m;
	for (k = 0; k < 2; k++)                            //在相应的列中选主元//
	{
		m = k;
		for (i = k + 1; i < 3; i++)
		{
			if (fabs(a[i][k]) > fabs(a[m][k]))
				m = i;
		}
		if (a[m][k] == 0)
		{
			printf("ERROR");
			return 0;
		}
		else                                           //两行进行比较交换两行//
		{
			for (j = 0; j < 3; j++)
			{
				temp = a[k][j];
				a[k][j] = a[m][j];
				a[m][j] = temp;
			}
			temp = b[m];
			b[m] = b[k];
			b[k] = temp;
		}
		for (i = k + 1; i <= 2; i++)
		{
			M = a[i][k] / a[k][k];
			b[i] = b[i] - M * b[k];
			for (j = 0; j < 3; j++)
			{
				a[i][j] = a[i][j] - M * a[k][j];
			}
		}
	}

	x[2] = b[2] / a[2][2];
	x[1] = (b[1] - x[2] * a[1][2]) / a[1][1];
	x[0] = (b[0] - x[2] * a[0][2] - x[1] * a[0][1]) / a[0][0];
	printf("x1 = %.10f\nx2 = %.10f\nx3 = %.10f\n", x[0], x[1], x[2]);
	return 0;
}
